package com.ithema.b2b.goodsprovider.controller;

import com.ithema.b2b.goodsprovider.dao.CartDao;
import model.Cart;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CartController {
    @Autowired
    CartDao cartDao;

    @GetMapping(value = "/getAllCart")
    public List<Cart> getAllCart(@RequestParam(value = "uid")int uid) {
        return cartDao.getAllCart(uid);
    }

    @GetMapping(value = "/insertCart")
    public int insertCart(@RequestParam(value = "goodsname")String goodsname,
                          @RequestParam(value = "number")int number,
                          @RequestParam(value = "price")int price,
                          @RequestParam(value = "goodid")int goodid,
                          @RequestParam(value = "uid")int uid) {
        return cartDao.insertCart(goodsname,number,price,goodid,uid);
    }

    @GetMapping(value = "/updateCart")
    public int updateCart(@RequestParam(value = "number")int number,
                          @RequestParam(value = "id")int id){
        return cartDao.updateCart(number,id);
    }

    @GetMapping(value = "/deleteCart")
    public int deleteCart(@RequestParam(value = "did")int did) {
        return cartDao.deleteCart(did);
    }
}
